package com.laker.autotest.core.retry;

import org.testng.IAnnotationTransformer;
import org.testng.IRetryAnalyzer;
import org.testng.annotations.ITestAnnotation;
import org.testng.internal.annotations.DisabledRetryAnalyzer;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class RetryAnnotationTransformer implements IAnnotationTransformer {

    @Override
    public void transform(ITestAnnotation testAnnotation, Class clazz, Constructor testConstructor, Method method) {
        Class<? extends IRetryAnalyzer> retryAnalyzerClass = testAnnotation.getRetryAnalyzerClass();
        if (retryAnalyzerClass == null || retryAnalyzerClass.equals(DisabledRetryAnalyzer.class)) {
            testAnnotation.setRetryAnalyzer(RetryAnalyzer.class);
        }

    }
}
